srsratio.n=function(data,N,s2r,mux,taux,param,B){ data=as.name(data); param=as.name(param) mux=mux; taux=taux; N=N; s2r=s2r; B=B if(param=='ratio'){ D=(B^2*mux^2)/4 } else if(param=='mean'){ D=B^2/4 } else if(param=='total'){ D=B^2/(N^2*4) } n=ceiling((N*s2r)/(N*D+s2r)) cat("","\n","Sample size estimation for SRS data ",data,"\n","Ratio estimation for ",param,"\n","N =",N, "Required bound =",B,'\n',"Estimated variance =",s2r,"\n","Mean of x (mu.x) =",mux,"\n","Total of x (taux) =",taux,"\n","Estimated sample size =",n,"\n") results=list(data=data,N=N,s2r=s2r,mux=mux,taux=taux,B=B,D=D,n=n) } # to use the function with its call: # srsratio.n(data,N,s2r,mux,taux,param,B) # data: name of dataset, in quotes # N: population size # s2r: variance=sum(y-rx)^2/(n-1) # mux: true mean of X or xbar # taux: true total of X, N*mux, or N*xbar # param: c('ratio','mean','total') # B: desired bound